package com.xjzd.std.lambda.util;

public class LambdaUtil {

    public static ThrowExceptionFunction isTure(boolean b) {
        return message -> {
            if (!b) {
                throw new RuntimeException(message);
            }
        };
    }

    public static BranchHandler isTrueOrFalse(boolean b) {
        return (trueHandler, falseHandler) -> {
            if (b) {
                trueHandler.run();
            } else {
                falseHandler.run();
            }
        };
    }

    public static <T> PresentOrElseHandler<? super T> isPresent(T o) {
        return (c, run) -> {
            if (o != null) {
                c.accept(o);
            } else {
                run.run();
            }
        };
    }
}
